import nProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from './router'
import store from './store'
nProgress.configure({
  showSpinner: false // 不显示圆环
})
const whiteList = ['/login']
router.beforeEach((to, from, next) => {
  const token = store.getters.token
  nProgress.start()
  if (token) {
    if (!store.getters.userInfo?.userId) {
      store.dispatch('user/getUserInfo')
    }
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
      nProgress.done()
    }
  }
})
router.afterEach((to, from, next) => {
  nProgress.done()
})
